﻿using Architecture.API.Application.TraceabilityCommand.TraceabilitiesCommand;
using MediatR;
using Traceability.Domain.BreedDomain;
using Traceability.Domain.Service.TraceabilitiesServices;

namespace Architecture.API.Application.TraceabilityCommandHandler.TraceabilitiesCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class UpdateTraceabilitiesCommandHandler : IRequestHandler<UpdateTraceabilitiesCommand, int>
    {

        /// <summary>
        /// 免疫服务
        /// </summary>
        protected readonly ITraceabilitiesService traceabilitiesService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="traceabilitiesService">免疫服务</param>
        public UpdateTraceabilitiesCommandHandler(ITraceabilitiesService traceabilitiesService)
        {
            this.traceabilitiesService = traceabilitiesService;
        }

        public async Task<int> Handle(UpdateTraceabilitiesCommand request, CancellationToken cancellationToken)
        {
            return await traceabilitiesService.UpdateTraceabilities(new Traceabilities() { TraceabilityId=request.TraceabilityId, FeedingDays = request.FeedingDays, ImmuneSystem = request.ImmuneSystem, ImmuneMethods = request.ImmuneMethods, ProductionBatch = request.ProductionBatch, ShoppingId = request.ShoppingId, UpdatedBy = request.UpdatedBy, UpdatedDate = DateTime.Now });
        }
    }
}
